package com.placement.refresh.util;

import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * purpose: This is a utility class to calculate date.
 * 
 * @author F020530/vipul
 *
 */
public class DateUtil {

	private static final Log logger = LogFactory.getLog(DateUtil.class);
	
	/**
	 * purpose: This method return calculated date for given date and number of days
	 * 			days can be positive or negative
	 * 			positive days will add the days to given date
	 * 			negative days will substract the days from the give date
	 * 
	 * @param date	:Date object
	 * @param days	:number of days to add/substract
	 * @return
	 */
	public static Date calculateDate(Date date,int days){
		Date calcDate = null;
//		logger.debug(">> getDate>> date:"+ date);
//		logger.debug(">> getDate>> days:"+ days);
		GregorianCalendar cal = new GregorianCalendar();
//		logger.debug(">>calculateDate>> cal.date:"+cal.getTimeInMillis());
		cal.setTimeInMillis(date.getTime());
//		logger.debug(">>calculateDate>> cal.date:"+cal.getTimeInMillis());
		cal.add(cal.DATE, days);
//		logger.debug(">>calculateDate>> cal.date:"+cal.getTimeInMillis());
		calcDate = new Date(cal.getTimeInMillis());
//		logger.debug(">> getDate>> calcDate:"+ calcDate);
		return calcDate;
	}
}
